package com.young.ums.cloud.api.feign;

import com.young.interfaces.ums.model.*;
import com.young.ums.cloud.api.feign.fallback.UmsOutServiceFeignFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2019/12/25 0025.
 */
@FeignClient(value = "young-ums", fallback = UmsOutServiceFeignFallback.class)
public interface IUmsOutServiceFeign {
    /**
     * 根据用户ID获取用户包含的资源列表
     * @param userId
     * @return
     * @throws Exception
     */
    @PostMapping("/ums-api/getNavigateByUserId")
    List<Navigate> getNavigateByUserId(@RequestParam(value = "userId") String userId);

    /**
     * 根据用户id获取资源树(获取菜单),暂未实现
     * @param userId
     * @return
     * @throws Exception
     */
    @PostMapping("/ums-api/getNavigateAsTreeByUserId")
    List<Navigate> getNavigateAsTreeByUserId(@RequestParam(value = "userId") String userId);

    /**
     * 根据用户id获取用户登录信息
     * @param userId
     * @return
     * @throws Exception
     */
    @PostMapping("/ums-api/getLoginUserById")
    User getLoginUserById(@RequestParam(value = "userId") String userId);

    /**
     * 验证单点,即验证token合法性
     * @param token 令牌
     * @return
     * @throws Exception
     */
    @PostMapping("/ums-api/verifySSO")
    SsoVerifyDTO verifySSO(@RequestParam(value = "token") String token);

    /**
     * 查询用户上一次登录的时间
     * @param userId
     * @return
     * @throws Exception
     */
    @PostMapping("/ums-api/getLastLoginTime")
    Date getLastLoginTime(@RequestParam(value = "userId") String userId);

    /**
     * 根据组织id获取组织信息
     * @param deptId
     * @return
     * @throws Exception
     */
    @PostMapping("/ums-api/getDeptById")
    Dept getDeptById(@RequestParam(value = "deptId") String deptId);

    /**
     * 根据角色id获取角色信息
     * @param roleId
     * @return
     * @throws Exception
     */
    @PostMapping("/ums-api/getRoleById")
    Role getRoleById(@RequestParam(value = "roleId") String roleId);

    /**
     * 判断是否存在指定id/account的用户
     * 在创建用户之前做唯一性验证
     * @param userIdOrAccount 用户id或者登陆账号
     * @return
     * @throws Exception
     */
    @PostMapping("/ums-api/existUserIdOrAccount")
    boolean existUserIdOrAccount(@RequestParam(value = "userIdOrAccount") String userIdOrAccount);

    /**
     * 创建用户,供外部调用,id/account/companyId不允许为空
     * @param user
     * @return
     * @throws Exception
     */
    @PostMapping("/ums-api/insertUser")
    boolean insertUser(@RequestBody User user);

    /**
     * 更新用户信息
     * @param user
     * @return int 改动的数据条数,-1表示操作失败
     * @throws Exception
     */
    @PostMapping("/ums-api/updateUser")
    int updateUser(@RequestBody User user);

    /**
     * 删除用户
     * @param userId 用户id
     * @return int 改动的数据条数,-1表示操作失败
     * @throws Exception
     */
    @PostMapping("/ums-api/deleteUser")
    int deleteUser(@RequestParam(value = "userId") String userId);

    /**
     * 校验用户是否有权限访问uri
     * @param userId 用户id
     * @param uri uri
     * @return
     */
    @PostMapping("/ums-api/canAccessUri")
    boolean canAccessUri(@RequestParam(value = "userId") String userId, @RequestParam(value = "uri") String uri);
}
